<template>
    <div class="wl-router-page">
        <Row :gutter="16" class="drawer">
            <Col v-for="(item, index) in drawerList" :key="index" span="6">
                <Alert @click.native="goToRouterPage(item.type)">
                    <span class="corner-mark">{{item.completedNum}}/{{item.totalNum}}</span>
                    <span class="alert-title">{{item.name}}</span>
                    <a class="clear-btn" v-if="companyCode == 'LA00085'" type="text" @click.stop="clearAction(item.type)">清空</a>
                </Alert>
            </Col>
        </Row>
        <Row :gutter="16" class="drawer">
            <Col span="6">
                <!--<Alert @click.native="goToRouterPage(11)">项目管理</Alert>-->
                <Alert @click.native="capitalAction" >资金管理</Alert>
            </Col>
            <Col span="6">
                <!--<Alert @click.native="goToRouterPage(12)">资金管理</Alert>-->
                <Alert @click.native="tipAction">项目管理</Alert>
            </Col>
            <Col span="6">
                <!--<Alert @click.native="goToRouterPage(13)">资产管理</Alert>-->
                <Alert @click.native="tipAction">资产管理</Alert>
            </Col>
            <Col span="6">
                <!--<Alert @click.native="goToRouterPage(14)">人事管理</Alert>-->
                <Alert @click.native="tipAction">人事管理</Alert>
            </Col>
        </Row>
    </div>
</template>

<script>
import { getGovPowersNumList, deleteAllItem } from '@/api/setting/router-page'
export default {
  data () {
    return {
      drawerList: [
        {
          name: '行政征收',
          type: 1,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '行政裁决',
          type: 2,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '行政给付',
          type: 3,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '行政奖励',
          type: 4,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '行政确认',
          type: 5,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '行政许可',
          type: 6,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '行政强制',
          type: 7,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '行政检查',
          type: 8,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '行政处罚',
          type: 9,
          totalNum: 0,
          completedNum: 0
        },
        {
          name: '其他权力',
          type: 10,
          totalNum: 0,
          completedNum: 0
        }
      ]
    }
  },
  computed: {
    companyCode () {
      return this.$store.state.user.severUserInfo.data.company_code
    }
  },
  methods: {
    clearAction (type) {
      // console.log('----', type)
      this.$Modal.confirm({
        title: '确认清空全部已填报数据？',
        content: '此操作仅清除本机构填报的事项',
        loading: true,
        onOk: () => {
          deleteAllItem({ type: type }).then(ret => {
            let data = ret.data
            if (data.errcode === 0) {
              this.$Modal.remove()
              this.init()
              this.success()
            } else {
              this.$Modal.remove()
              this.error(data)
            }
          })
        }
      })
    },
    goToRouterPage (type) {
      this.$router.push({
        query: { type: type },
        name: 'rulePageList'
      })
    },
    capitalAction () {
      this.$router.push({
        name: 'capitalManage'
      })
    },
    tipAction () {
      this.$Message.info('暂未上线！')
    },
    init () {
      getGovPowersNumList().then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          data.data.forEach(item => {
            this.drawerList.forEach(item2 => {
              if (item.type.toString() === item2.type.toString()) {
                item2.completedNum = item.hang_air_num
                item2.totalNum = item.sueess_num
              }
            })
          })
        } else {
          this.error(data)
        }
      })
    },
    success (val) {
      val = this.$common.xeUtils.isEmpty(val) ? '操作成功' : val
      this.$Message.success(val)
    },
    error (data) {
      this.$Message.error({
        content: '操作失败,\n' + data.errmsg
      })
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped lang="less">
    .wl-router-page {
        .drawer /deep/ .ivu-alert-info {
             min-height: 100px;
         }

        .drawer /deep/ .ivu-alert {
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
        }

        .corner-mark {
            display: block;
            position: absolute;
            right: 10px;
            top: 10px;
        }

        .alert-title {
            display: block;
        }

        .clear-btn {
            display: block;
            position: absolute;
            right: 10px;
            bottom: 10px;
        }
    }
</style>
